export interface GenericChatEvent<T extends string, D extends object> {
  type: T;
  data: D;
}

export interface StartOfReportEvent
  extends GenericChatEvent<"start_of_report", { report_id: string }> {}

export interface EndOfReportEvent
  extends GenericChatEvent<"end_of_report", { report_id: string }> {}

export interface StartOfWorkflowEvent
  extends GenericChatEvent<
    "start_of_workflow",
    { workflow_id: string; input: { content: string }[] }
  > {}

export interface EndOfWorkflowEvent
  extends GenericChatEvent<
    "end_of_workflow",
    { workflow_id: string; messages: { role: string; content: string }[] }
  > {}

export interface FinalSessionStateEvent
  extends GenericChatEvent<
    "final_session_state",
    { messages: { role: string; content: string }[] }
  > {}

export interface StartOfAgentEvent
  extends GenericChatEvent<
    "start_of_agent",
    { agent_id: string; agent_name: string }
  > {}

export interface EndOfAgentEvent
  extends GenericChatEvent<"end_of_agent", { agent_id: string }> {}

export interface ToolCallEvent
  extends GenericChatEvent<
    "tool_call",
    { tool_call_id: string; tool_name: string; tool_input: Record<string, any> }
  > {}

export interface ToolCallResultEvent
  extends GenericChatEvent<
    "tool_call_result",
    { tool_call_id: string; tool_result: string }
  > {}

export interface StartOfLLMEvent
  extends GenericChatEvent<"start_of_llm", { agent_name: string }> {}

export interface EndOfLLMEvent
  extends GenericChatEvent<"end_of_llm", { agent_name: string }> {}

export interface MessageEvent
  extends GenericChatEvent<
    "message",
    {
      message_id: string;
      delta: { content?: string; reasoning_content?: string };
    }
  > {}

// 新增会话ID事件类型
export interface SessionIdEvent
  extends GenericChatEvent<
    "session_id",
    {
      session_id: string;
    }
  > {}

export type ChatEvent =
  | StartOfReportEvent
  | EndOfReportEvent
  | StartOfWorkflowEvent
  | EndOfWorkflowEvent
  | StartOfAgentEvent
  | EndOfAgentEvent
  | FinalSessionStateEvent
  | ToolCallEvent
  | ToolCallResultEvent
  | StartOfLLMEvent
  | EndOfLLMEvent
  | MessageEvent
  | SessionIdEvent

export type TeamMember = {
  name: string;
  desc: string;
  is_optional: boolean;
};
// 会话消息类型
export interface SessionMessage {
  id: string;
  role: string; // 'user' 或 'assistant'
  type: string; // 'text' 或 'workflow'
  content: any; // 文本内容或工作流对象
  created_at: string; // ISO 8601 时间字符串
  username: string;
}

// 会话状态类型
export interface SessionState {
  messages?: any[]; // 具体的状态数据结构根据实际情况定义
  // 可以包含其他状态字段
  [key: string]: any;
}

// 会话历史响应类型
export interface SessionHistoryResponse {
  session_id: string;
  username: string;
  messages: SessionMessage[];
  state: SessionState;
}

// 会话列表项类型
export interface SessionListItem {
  session_id: string;
  created_at: string; // ISO 8601 时间字符串
  updated_at: string; // ISO 8601 时间字符串
  preview: string | null;
}